package com.yjd.bi.jf.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yjd.bi.jf.dao.IJfOrderDao;
import com.yjd.bi.jf.enums.JfOrderStatusEnum;
import com.yjd.bi.jf.model.JfOrderModel;
import com.yjd.bi.jf.service.IJfIntegralDataService;
import com.yjd.bi.jf.service.IJfIntegralService;
import com.yjd.bi.jf.service.IJfOrderDetailService;
import com.yjd.bi.jf.service.IJfOrderService;
import com.yjd.comm.base.dao.IBaseDao;
import com.yjd.comm.base.enums.DbWREnums;
import com.yjd.comm.base.model.PagerModel;
import com.yjd.comm.base.service.impl.BaseServiceImpl;
import com.yjd.comm.util.FrameUtil;

/**
 * <b>description</b>：会员年积分流水表业务实现<br>
 * <b>time</b>：2017-03-07 15:13:07 <br>
 * <b>author</b>： ready percy-chen@hotmail.com
 */
@Service("jfOrderService")
public class JfOrderServiceImpl extends BaseServiceImpl implements
	IJfOrderService {

    /**
     * 插入
     * 
     * @param model
     * @return
     * @throws Exception
     */
    public JfOrderModel insert(JfOrderModel model) throws Exception {
	return this.jfOrderDao.insertModel(model, true);
    }

    /**
     * 更新
     * 
     * @param model
     * @return
     * @throws Exception
     */
    public int update(JfOrderModel model) throws Exception {
	return this.jfOrderDao.updateModel(model, true);
    }

    /**
     * 根据id删除
     * 
     * @param id
     * @return
     * @throws Exception
     */
    public int delete(long id) throws Exception {
	Map<Object, Object> paramMap = new HashMap<Object, Object>();
	paramMap.put("id", id);
	return this.jfOrderDao.deleteModel(paramMap, true);
    }


    @SuppressWarnings("unchecked")
    @Override
    public void orderStatusFinishHandle(Long order_id) throws Exception {
	JfOrderModel orderModel = jfOrderDao.getModelById(order_id, true);
	if (orderModel == null) {
	    FrameUtil.throwBaseException1("订单记录不存在");
	}

	if (jfOrderDao.updateByMap(FrameUtil.newHashMap("id",
		orderModel.getId(), "status",
		JfOrderStatusEnum.FINISH_ORDER.getCode(), "update_time",
		FrameUtil.getTime(null)), true) != 1) {
	    FrameUtil.throwBaseException1("订单完成状态更新失败");

	}

    }
    
    
    

    @Override
    public PagerModel getOrderList(Map<String, Object> param)
	    throws Exception {
	return this.getPageModel(param, "getOrderList", DbWREnums.READ);
    }




    @Resource
    private IJfIntegralDataService jfIntegralDataService;

    @Resource
    private IJfOrderDetailService jfOrderDetailService;

    @Resource
    private IJfIntegralService jfIntegralService;


    @Resource
    private IJfOrderDao jfOrderDao;

    @Override
    public IBaseDao getBaseDao() {
	return this.jfOrderDao;
    }

}
